function createStore(reducer) {
  //state是存储在store中的数据
  let state;
  //一个队列
  let listeners = [];

  function getState() {
    return state;
  }
  //订阅
  function subscribe(callback) {
    listeners.push(callback);
  }
  //发布
  function dispatch(action) {
    state = reducer(state, action);
    for (let i = 0; i < listeners.length; i++) {
      let listener = listeners[i];
      listener();
    }
  }

  let store = {
    getState,
    //订阅
    subscribe,
    //发布
    dispatch,
  };

  //在store初始化的时候需要执行一次reducer
  state = reducer(state, {
    type: '@@init/redux.x.x.x',
  });
  return store;
}

window.Redux = {};
Redux.createStore = createStore;
